from fastmcp  import Client
import json
import asyncio

#sse_url = "http://127.0.0.1:8931/sse"
sse_url = "https://mcp.amap.com/sse?key=高德地图的key"
client = Client(sse_url)

#拿到所有的工具
async def list_tools():
    async with client:
        if client is None:
            return None
        tools = await client.list_tools()
        print(tools)
        return tools
#拿到所有的prompts
async def list_prompt():
    async with client:
        prompts = await client.list_prompts()
        print(prompts)
        return prompts

async def get_tool(data:str):
    server_result=None
    """调用工具"""
    async with client:
        input_json = json.loads(data)
        function_name = input_json["name"]
        parameters = input_json["arguments"]
        if function_name :
            server_result = await client.call_tool(function_name, parameters)
    if server_result:
        return str(server_result[0].text)
    else:
        return None

if __name__ == "__main__":
    #aa = asyncio.run(get_tool('{"function_name":"get_city_weather","parameters":{"city":"北京"}}'))
    #aa = asyncio.run(list_tools())
    aa = asyncio.run(get_tool('{"name": "maps_weather", "arguments": {"city": "南宁"}}'))
    #aa = asyncio.run(get_tool('{"name": "browser_navigate", "arguments": {"url": "https://www.bilibili.com/"}}'))
    print(aa)